(deftemplate total (slot pret))
(deftemplate produs (declare (slot-specific TRUE)) (slot nume) (slot pret))
(deftemplate produsAlimentar extends produs (slot calorii) (slot unitateMasura))
(deftemplate produsUzCasnic extends produs (slot putereConsumata))
(deftemplate produsConstructii extends produs (slot unitateMasura))

(assert (produsAlimentar (nume verdeturi) (pret 1) (calorii 10) (unitateMasura bucata)))
(assert (produsAlimentar (nume carne) (pret 10) (calorii 50) (unitateMasura kg)))
(assert (produsUzCasnic (nume cana) (pret 3) (putereConsumata 0)))
(assert (produsUzCasnic (nume mixer) (pret 35) (putereConsumata 100)))
(assert (produsConstructii (nume scandura) (pret 20) (unitateMasura mc)))
(assert (produsConstructii (nume ciocan) (pret 10) (unitateMasura bucata)))
(assert (total (pret 0)))

(defrule afisare
    (produs (nume ?n))
    =>
    (printout t "Nume: " ?n crlf)
    )
(defrule suma
    ?idr<-(total (pret ?p))
    ?idrp<-(produs (pret ?pp))
    =>
    (bind ?r (+ ?p ?pp))
    (modify ?idr (pret ?r))
    (retract ?idrp)
    )
(defrule total
    (total (pret ?t))
    =>
    (printout t "Total: " ?t crlf))
(run)
